<?php
/**
 * Created by PhpStorm.
 * User: lcz
 * Date: 2018/8/15
 * Time: 17:55
 * 文章
 */

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

class Article extends Api {
	
	protected $noNeedRight = ['*'];
	protected $noNeedLogin = ['*'];
	
	
	/**
	 * 文章列表
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \think\exception\DbException
	 */
	public function index(){
		$rows = Db::name('Article')
			->order(['sort' => 'ASC', 'create_time' => 'DESC'])
			->field('id, title, content, from_unixtime(create_time) as time, image')
			->select();
		$this->success(__('查询成功'), $rows);
	}
	
	/**
	 * 文章列表
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \think\exception\DbException
	 */
	public function detail(){
		$id = input('post.id', '', 'int');
		if(!$id || $id < 0) {
			$this->error(__('参数错误'));
		}
		
		
		$rows = Db::name('Article')
			->field('id, title, content, from_unixtime(create_time) as time, image')
			->find($id);
		$this->success(__('查询成功'), $rows);
	}
	
}
